package org.come.until;

import com.tool.tcp.GlowFilter;
import org.apache.commons.lang.StringUtils;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.TestPetJpanel1;
import org.come.MountShouHu.AllMountShouhu;
import org.come.bean.*;
import org.come.entity.*;
import org.come.model.*;
import com.tool.ModerateTask.TaskSet;
import com.tool.ModerateTask.TaskData;

import java.util.ArrayList;

import java.util.TreeMap;
import java.util.Comparator;
import java.math.BigDecimal;
import org.come.Jpanel.TestPetJpanel;
import org.come.mouslisten.GoodsMouslisten;
import org.come.socket.DownLoadTxt;

import com.tool.ModerateTask.AllTask;

import java.util.Map;

import org.come.model.Eshop;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class UserMessUntil {
    private static List<RewardHall> RewardHallArr;
    private static List<Friendtable> friendtables;
    private static List<RoleSummoning> petListTable;
    private static RoleSummoning ChosePetMes;
    private static List<Baby> MyListBaby;
    private static String chatFriendName;
    private static volatile AllMapBean allmapbean;
    private static NpcShopBean npcshop;
    private static RoleExpBean petAndPlayerExp;
    private static List<Eshop> eshops;
    private static SkillBean skillBean;
    private static AllBabyResult allBabyResult;
    private static GoodsBean goodsBean;
    private static RobotsBean robotBean;
    private static AllNpcBean allNpcBean;
    private static AllDoorBean allDoorBean;
    private static AllBbuy allBbuy;
    private static AllTalent allTalent;
    private static AllColorScheme allColorScheme;
    private static AllTx allTx;
    public static AllSuit allSuit;
    public static AllGuide allGuide;
    public static Map<String, String> allTYC;
    private static AllACard allACard;
    private static AllTitleBean allTitle;
    private static AllEventModelBean allEvent;
    private static AllTask allTask;
    private static AllPal allPal;
    private static allPetExchange allPetExchange;
    private static AllActive allActive;
    private static AllAchieve allAchieve;
    private static AllLianHua allLianHua;
    private static AllMeridians allMeridians;
    private static allGoodsExchange allGoodsExchange;
    private static allItemExchange allItemExchange;
    private static GMshopItemBean allGMshopItem;
    private static ConfigureBean allConfigure;
    private static ConcurrentHashMap<String, ShaoXiangLimit> allshaoxianglimit;
    private static List<String> allshaoxiang;
    private static List<QianDao> qianDaoList;

    private static AllHallucination allHallucination;

    private static AllPet allPet;
    // 寄存召唤兽信息list
    private static List<RoleSummoning> depositPetListTable = new ArrayList<>();
    private static PetExpBean petExp;

    private static AutoActiveBaseBean alltutoactive;

    private static AutoActiveRedisBaseBean autoActiveRedisBaseBean;

    private static AllAchievement allAchievement;

    // 添加弱引用缓存，避免内存泄漏
    private static final Map<String, Object> cache = new ConcurrentHashMap<>();
    private static final long CACHE_TIMEOUT = 300000; // 5分钟缓存超时

    // 添加定时清理缓存的机制
    private static final long CACHE_CLEANUP_INTERVAL = 30000; // 30秒
    private static long lastCacheCleanup = 0;

    public static void checkAndClearCache() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - lastCacheCleanup > CACHE_CLEANUP_INTERVAL) {
            clearExpiredCache();
            lastCacheCleanup = currentTime;
        }
    }

    // 缓存条目类
    private static class CacheEntry {
        Object value;
        long timestamp;

        CacheEntry(Object value) {
            this.value = value;
            this.timestamp = System.currentTimeMillis();
        }

        boolean isExpired() {
            return System.currentTimeMillis() - timestamp > CACHE_TIMEOUT;
        }
    }

    public static Skill getskill1(final String tmp) {
        for (final String key : getSkillBean().getSkillMap().keySet()) {
            if (((Skill)getSkillBean().getSkillMap().get(key)).getSkillname().equals(tmp)) {
                return (Skill)getSkillBean().getSkillMap().get(key);
            }
        }
        return null;
    }

    public static Skill getSkillById(final String tmp) {
        for (final String key : getSkillBean().getSkillMap().keySet()) {
            if (((Skill)getSkillBean().getSkillMap().get(key)).getSkillid().equals(tmp)) {
                return (Skill)getSkillBean().getSkillMap().get(key);
            }
        }
        return null;
    }

    // 添加缓存清理方法
    public static void clearExpiredCache() {
        cache.entrySet().removeIf(entry -> {
            if (entry.getValue() instanceof CacheEntry) {
                return ((CacheEntry) entry.getValue()).isExpired();
            }
            return false;
        });
    }

    // 添加完整缓存清理方法
    public static void clearAllCache() {
        cache.clear();
        // 清理各个静态变量
        allmapbean = null;
        npcshop = null;
        petAndPlayerExp = null;
        eshops = null;
        skillBean = null;
        allBabyResult = null;
        goodsBean = null;
        robotBean = null;
        allNpcBean = null;
        allDoorBean = null;
        allBbuy = null;
        allTalent = null;
        allColorScheme = null;
        allTx = null;
        allSuit = null;
        allGuide = null;
        allTYC = null;
        allACard = null;
        allTitle = null;
        allEvent = null;
        allTask = null;
        allPal = null;
        allPetExchange = null;
        allActive = null;
        allAchieve = null;
        allLianHua = null;
        allMeridians = null;
        allGoodsExchange = null;
        allItemExchange = null;
        allGMshopItem = null;
        allConfigure = null;
        allshaoxianglimit = null;
        allshaoxiang = null;
        qianDaoList = null;
        allHallucination = null;
        allPet = null;
        petExp = null;
        alltutoactive = null;
        autoActiveRedisBaseBean = null;
        allAchievement = null;
        System.gc(); // 建议进行垃圾回收
    }

    private static AllActive allVipActive;
    public static AllActive getAllVipActive() {
        String cacheKey = "allVipActive";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllActive) entry.value;
        }

        if (allVipActive == null) {
            DownLoadTxt.getDownLoadTxt().initMes("vipActive.txt");
        }

        cache.put(cacheKey, new CacheEntry(allVipActive));
        return allVipActive;
    }

    public static void setAllVipActive(AllActive allVipActive) {
        UserMessUntil.allVipActive = allVipActive;
        cache.put("allVipActive", new CacheEntry(allVipActive));
    }

    public static void setQianDaoList(List<QianDao> qianDaoList) {
        UserMessUntil.qianDaoList = qianDaoList;
        cache.put("qianDaoList", new CacheEntry(qianDaoList));
    }

    public static List<QianDao> getQiandaoBean() {
        String cacheKey = "qianDaoList";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (List<QianDao>) entry.value;
        }

        if (qianDaoList == null) {
            DownLoadTxt.getDownLoadTxt().initMes("qiandao.txt");
        }

        cache.put(cacheKey, new CacheEntry(qianDaoList));
        return qianDaoList;
    }

    public static AllNpcBean getNpctable() {
        String cacheKey = "allNpcBean";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllNpcBean) entry.value;
        }

        if (allNpcBean == null) {
            DownLoadTxt.getDownLoadTxt().initMes("npc.txt");
        }

        cache.put(cacheKey, new CacheEntry(allNpcBean));
        return allNpcBean;
    }

    public static String getChatFriendName() {
        return UserMessUntil.chatFriendName;
    }

    public static void setChatFriendName(final String chatFriendName) {
        UserMessUntil.chatFriendName = chatFriendName;
    }

    public static RoleExpBean getPetAndPlayerExp() {
        String cacheKey = "petAndPlayerExp";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (RoleExpBean) entry.value;
        }

        return UserMessUntil.petAndPlayerExp;
    }

    public static RoleSummoning getChosePetMes() {
        return UserMessUntil.ChosePetMes;
    }

    public static Skill getSkillId(final String id) {
        return (Skill)getSkillBean().getSkillMap().get(id);
    }

    public static SkillBean getSkillBean() {
        String cacheKey = "skillBean";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (SkillBean) entry.value;
        }

        if (UserMessUntil.skillBean == null) {
            DownLoadTxt.getDownLoadTxt().initMes("skill.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.skillBean));
        return UserMessUntil.skillBean;
    }

    public static void setChosePetMes(final RoleSummoning chosePetMes) {
        UserMessUntil.ChosePetMes = chosePetMes;
        TestPetJpanel.part = null;
        TestPetJpanel1.part = null;
//        这里是召唤兽界面和召唤界面选择召唤兽显示对应宠物tcp
    }

    public static void unsetChosePetMes() {
        UserMessUntil.ChosePetMes = null;
        TestPetJpanel.part = null;
        TestPetJpanel1.part = null;
//        这里是召唤兽界面和召唤界面选择召唤兽显示对应宠物tcp
    }

    public static List<Eshop> getEshops() {
        String cacheKey = "eshops";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (List<Eshop>) entry.value;
        }

        if (UserMessUntil.eshops == null) {
            DownLoadTxt.getDownLoadTxt().initMes("eshop.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.eshops));
        return UserMessUntil.eshops;
    }

    public static void setEshops(final List<Eshop> eshops) {
        UserMessUntil.eshops = eshops;
        cache.put("eshops", new CacheEntry(eshops));
    }

    public static AllMapBean getAllmapbean() {
        String cacheKey = "allmapbean";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllMapBean) entry.value;
        }

        if (UserMessUntil.allmapbean == null) {
            DownLoadTxt.getDownLoadTxt().initMes("map.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allmapbean));
        return UserMessUntil.allmapbean;
    }

    public static void setAllmapbean(final AllMapBean allmapbean) {
        UserMessUntil.allmapbean = allmapbean;
        cache.put("allmapbean", new CacheEntry(allmapbean));
    }

    public static NpcShopBean getNpcshop() {
        String cacheKey = "npcshop";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (NpcShopBean) entry.value;
        }

        if (UserMessUntil.npcshop == null) {
            DownLoadTxt.getDownLoadTxt().initMes("npcshop.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.npcshop));
        return UserMessUntil.npcshop;
    }


    //重置时间锁
    public static void releaseTimeLock(RoleSummoning chosePetMes){

        if(chosePetMes.getTimeLock() != null && System.currentTimeMillis() >= chosePetMes.getTimeLock() && chosePetMes.getPetTimeLock() == 1){

            ZhuFrame.getZhuJpanel().addPrompt("#R" + chosePetMes.getSummoningname()+ " #Y时间锁已解除!");
            //更新时间锁
            chosePetMes.setPetTimeLock(0);
            chosePetMes.setTimeLock(0l);
            try {
                SendRoleAndRolesummingUntil.sendRoleSumming(chosePetMes);
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }



    }

    //重置时间锁
    public static void releaseTableTimeLock(Goodstable goodstable){

        if( goodstable != null && goodstable.getGoodTimeLock() == 2 && System.currentTimeMillis() >= goodstable.getGoodTimeLockDuration() ){

            ZhuFrame.getZhuJpanel().addPrompt("#R" + goodstable.getGoodsname()+ " #Y时间锁已解除!");
            //更新时间锁
            goodstable.setGoodTimeLock(0);
            goodstable.setGoodTimeLockDuration(0l);
            try {
                GoodsMouslisten.gooduse(goodstable,0);
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

    }



    public static void setNpcshop(final NpcShopBean npcshop) {
        UserMessUntil.npcshop = npcshop;
        cache.put("npcshop", new CacheEntry(npcshop));
    }

    public static RoleExpBean getExp() {
        String cacheKey = "petAndPlayerExp";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (RoleExpBean) entry.value;
        }

        if (UserMessUntil.petAndPlayerExp == null) {
            DownLoadTxt.getDownLoadTxt().initMes("exp.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.petAndPlayerExp));
        return UserMessUntil.petAndPlayerExp;
    }

    public static void setPetAndPlayerExp(final RoleExpBean petAndPlayerExp) {
        UserMessUntil.petAndPlayerExp = petAndPlayerExp;
        cache.put("petAndPlayerExp", new CacheEntry(petAndPlayerExp));
    }

    public static List<Friendtable> getFriendtables() {
        return UserMessUntil.friendtables;
    }

    public static void setFriendtables(final List<Friendtable> friendtables) {
        UserMessUntil.friendtables = friendtables;
    }

    public static List<RoleSummoning> getPetListTable() {
        return UserMessUntil.petListTable;
    }

    public static RoleSummoning getPetRgid(final BigDecimal rgid) {
        if (rgid == null) {
            return (RoleSummoning)UserMessUntil.petListTable.get(0);
        }
        for (int i = 0; i < UserMessUntil.petListTable.size(); ++i) {
            if (((RoleSummoning)UserMessUntil.petListTable.get(i)).getSid().compareTo(rgid) == 0) {
                return (RoleSummoning)UserMessUntil.petListTable.get(i);
            }
        }
        return null;
    }

    public static AllPet getAllPet() {
        String cacheKey = "allPet";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllPet) entry.value;
        }

//        if (UserMessUntil.allPet == null) {
        DownLoadTxt.getDownLoadTxt().initMes("pet.txt");
//        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allPet));
        return UserMessUntil.allPet;
    }

    public static List<RoleSummoning> getRoleSummoningList() {
        List<RoleSummoning> list = new ArrayList<>();
        return list;
    }

    public static void setAllPet(AllPet allPet) {
        UserMessUntil.allPet = allPet;
        cache.put("allPet", new CacheEntry(allPet));
    }

    public static void setPetListTable(final List<RoleSummoning> petListTable) {
        UserMessUntil.petListTable = petListTable;
    }

    public static Baby getbaby(final BigDecimal babyid) {
        if (UserMessUntil.MyListBaby == null) {
            return null;
        }
        if (babyid == null) {
            return null;
        }
        for (int i = UserMessUntil.MyListBaby.size() - 1; i >= 0; --i) {
            if (((Baby)UserMessUntil.MyListBaby.get(i)).getBabyid().compareTo(babyid) == 0) {
                return (Baby)UserMessUntil.MyListBaby.get(i);
            }
        }
        return null;
    }

    public static List<Baby> getMyListBaby() {
        return UserMessUntil.MyListBaby;
    }

    public static void setMyListBaby(final List<Baby> myListBaby) {
        UserMessUntil.MyListBaby = myListBaby;
    }

    public static GoodsBean getGoodsBean() {
        String cacheKey = "goodsBean";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (GoodsBean) entry.value;
        }

        if (UserMessUntil.goodsBean == null) {
            DownLoadTxt.getDownLoadTxt().initMes("goods.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.goodsBean));
        return UserMessUntil.goodsBean;
    }

    public static void main(final String[] args) {
        final Map<BigDecimal, Goodstable> map = getGoodsBean().getAllGoodsMap();
        @SuppressWarnings("unchecked")
        final Map<BigDecimal, Goodstable> sortMap = (Map<BigDecimal, Goodstable>)new TreeMap((Comparator<? super BigDecimal>)new Comparator<BigDecimal>() {
            @Override
            public int compare(final BigDecimal str1, final BigDecimal str2) {
                return str1.compareTo(str2);
            }
        });
        sortMap.putAll(map);
        sortMap.forEach((key, value) -> {
            if (key.compareTo(new BigDecimal(745)) == 0) {
                //system.out.println(1111);
            }
            if (key.compareTo(new BigDecimal(10080)) == 0) {
                //system.out.println(1111);
            }
            //system.out.println(key + "-" + value.getGoodsname() + "-");
            return;
        });
    }

    public static Goodstable getgoodstable(final BigDecimal bigDecimal) {
//    	GoodsBean sda = getGoodsBean();
        getGoodsBean();
//    	Map<BigDecimal, Goodstable> msp = UserMessUntil.goodsBean.getAllGoodsMap();
//    	//system.out.println(msp);


//    	for (Map.Entry<BigDecimal, Goodstable> entry : msp.entrySet()) {
//            //system.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
//        }
        Goodstable goodstable = UserMessUntil.goodsBean.getAllGoodsMap().get(bigDecimal);
        return goodstable;
    }

    public static void setGoodsBean(final GoodsBean goodsBean) {
        UserMessUntil.goodsBean = goodsBean;
        cache.put("goodsBean", new CacheEntry(goodsBean));
    }

    public static void setSkillBean(final SkillBean skillBean) {
        UserMessUntil.skillBean = skillBean;
        cache.put("skillBean", new CacheEntry(skillBean));
    }

    public static RobotsBean getRobotBean() {
        String cacheKey = "robotBean";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (RobotsBean) entry.value;
        }

        if (UserMessUntil.robotBean == null) {
            DownLoadTxt.getDownLoadTxt().initMes("robots.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.robotBean));
        return UserMessUntil.robotBean;
    }

    public static Robots getRobot(final String type) {
        getRobotBean();
        return (Robots)UserMessUntil.robotBean.getRobotsMap().get(type);
    }

    public static void setRobotBean(final RobotsBean robotBean) {
        UserMessUntil.robotBean = robotBean;
        cache.put("robotBean", new CacheEntry(robotBean));
    }

    public static NpcInfoBean getnpc(final String type) {
        getAllNpcBean();
        return (NpcInfoBean)UserMessUntil.allNpcBean.getAllNpcInfo().get(type);
    }

    public static AllNpcBean getAllNpcBean() {
        String cacheKey = "allNpcBean";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllNpcBean) entry.value;
        }

        if (UserMessUntil.allNpcBean == null) {
            DownLoadTxt.getDownLoadTxt().initMes("npc.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allNpcBean));
        return UserMessUntil.allNpcBean;
    }

    public static void setAllNpcBean(final AllNpcBean allNpcBean) {
        UserMessUntil.allNpcBean = allNpcBean;
        cache.put("allNpcBean", new CacheEntry(allNpcBean));
    }

    public static Door getDoor(final String type) {
        getAllDoorBean();
        return (Door)UserMessUntil.allDoorBean.getAlldoor().get(type);
    }

    public static AllDoorBean getAllDoorBean() {
        String cacheKey = "allDoorBean";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllDoorBean) entry.value;
        }

        if (UserMessUntil.allDoorBean == null) {
            DownLoadTxt.getDownLoadTxt().initMes("door.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allDoorBean));
        return UserMessUntil.allDoorBean;
    }

    public static void setAllDoorBean(final AllDoorBean allDoorBean) {
        UserMessUntil.allDoorBean = allDoorBean;
        cache.put("allDoorBean", new CacheEntry(allDoorBean));
    }

    public static Bbuy getBbuy(final BigDecimal goodsid) {
        getAllBbuy();
        return (Bbuy)UserMessUntil.allBbuy.getAllbbuy().get(Integer.valueOf(goodsid.intValue()));
    }

    public static AllBbuy getAllBbuy() {
        String cacheKey = "allBbuy";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllBbuy) entry.value;
        }

        if (UserMessUntil.allBbuy == null) {
            DownLoadTxt.getDownLoadTxt().initMes("bbuy.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allBbuy));
        return UserMessUntil.allBbuy;
    }

    public static void setAllBbuy(final AllBbuy allBbuy) {
        UserMessUntil.allBbuy = allBbuy;
        cache.put("allBbuy", new CacheEntry(allBbuy));
    }

    public static Talent getTalent(final int id) {
        getAllTalent();
        return (Talent)UserMessUntil.allTalent.getAllTalent().get(Integer.valueOf(id));
    }

    public static AllTalent getAllTalent() {
        String cacheKey = "allTalent";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllTalent) entry.value;
        }

        if (UserMessUntil.allTalent == null) {
            DownLoadTxt.getDownLoadTxt().initMes("talent.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allTalent));
        return UserMessUntil.allTalent;
    }

    public static void setAllTalent(final AllTalent allTalent) {
        UserMessUntil.allTalent = allTalent;
        cache.put("allTalent", new CacheEntry(allTalent));
    }

    public static ColorScheme getColor(final int id) {
        getAllColorScheme();
        return (ColorScheme)UserMessUntil.allColorScheme.getAllMap().get(Integer.valueOf(id));
    }

    public static ColorScheme getColor(final String color) {
        getAllColorScheme();
        for (final ColorScheme value : UserMessUntil.allColorScheme.getAllMap().values()) {
            if (value.getName().equals(color)) {
                return value;
            }
        }
        return null;
    }

    public static ColorScheme getColors(final int type) {
        getAllColorScheme();
        @SuppressWarnings({ "rawtypes", "unchecked" })
        final List<Integer> a = (List<Integer>)new ArrayList();
        for (final ColorScheme value : UserMessUntil.allColorScheme.getAllMap().values()) {
            if (value.getZid() == 0 || value.getZid() == type) {
                a.add(Integer.valueOf(value.getId()));
            }
        }
        if (a.size() == 0) {
            return null;
        }
        return (ColorScheme)UserMessUntil.allColorScheme.getAllMap().get(a.get(Util.random.nextInt(a.size())));
    }

    public static AllColorScheme getAllColorScheme() {
        String cacheKey = "allColorScheme";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllColorScheme) entry.value;
        }

        if (UserMessUntil.allColorScheme == null) {
            DownLoadTxt.getDownLoadTxt().initMes("color.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allColorScheme));
        return UserMessUntil.allColorScheme;
    }

    public static void setAllColorScheme(final AllColorScheme allColorScheme) {
        UserMessUntil.allColorScheme = allColorScheme;
        cache.put("allColorScheme", new CacheEntry(allColorScheme));
    }

    public static BabyResult getBabyResult(final String name) {
        getAllBabyResult();
        for (int i = UserMessUntil.allBabyResult.getAllBabyResults().size() - 1; i >= 0; --i) {
            final BabyResult babyResult = (BabyResult)UserMessUntil.allBabyResult.getAllBabyResults().get(i);
            if (babyResult.getNan().equals(name)) {
                return babyResult;
            }
            if (babyResult.getNv().equals(name)) {
                return babyResult;
            }
        }
        return (BabyResult)UserMessUntil.allBabyResult.getAllBabyResults().get(0);
    }

    public static NpcInfoBean getnpcfromID(String id) {
        getAllNpcBean();
        for (NpcInfoBean infoBean:allNpcBean.getAllNpcInfo().values()){
            if (infoBean.getNpctable().getNpcid().contains(id)){
                return infoBean;
            }
        }
        return null;
    }

    public static AllBabyResult getAllBabyResult() {
        String cacheKey = "allBabyResult";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllBabyResult) entry.value;
        }

        if (UserMessUntil.allBabyResult == null) {
            DownLoadTxt.getDownLoadTxt().initMes("babyresult.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allBabyResult));
        return UserMessUntil.allBabyResult;
    }

    public static void setAllBabyResult(final AllBabyResult allBabyResult) {
        UserMessUntil.allBabyResult = allBabyResult;
        cache.put("allBabyResult", new CacheEntry(allBabyResult));
    }

    public static List<RewardHall> getRewardHallArr() {
        return UserMessUntil.RewardHallArr;
    }

    public static void setRewardHallArr(final List<RewardHall> rewardHallArr) {
        UserMessUntil.RewardHallArr = rewardHallArr;
    }

    public static AllSuit getAllSuit() {
        String cacheKey = "allSuit";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllSuit) entry.value;
        }

        if (UserMessUntil.allSuit == null) {
            DownLoadTxt.getDownLoadTxt().initMes("suit.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allSuit));
        return UserMessUntil.allSuit;
    }

    public static RoleSuitBean getSuit(final int suid) {
        getAllSuit();
        return (RoleSuitBean)UserMessUntil.allSuit.getRolesuit().get(Integer.valueOf(suid));
    }

    public static void setAllSuit(final AllSuit allSuit) {
        UserMessUntil.allSuit = allSuit;
        cache.put("allSuit", new CacheEntry(allSuit));
    }

    private static AllMountShouhu allMountShouhu;
    public static AllMountShouhu getAllMountShouhu() {
        String cacheKey = "allMountShouhu";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllMountShouhu) entry.value;
        }

        if (UserMessUntil.allMountShouhu == null) {
            DownLoadTxt.getDownLoadTxt().initMes("shssx.txt");
        }

        cache.put(cacheKey, new CacheEntry(allMountShouhu));
        return allMountShouhu;
    }

    public static AllGuide getAllGuide() {
        String cacheKey = "allGuide";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllGuide) entry.value;
        }

        if (UserMessUntil.allGuide == null) {
            DownLoadTxt.getDownLoadTxt().initMes("guide.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allGuide));
        return UserMessUntil.allGuide;
    }

    public static void setAllGuide(final AllGuide allGuide) {
        UserMessUntil.allGuide = allGuide;
        cache.put("allGuide", new CacheEntry(allGuide));
    }

    public static RoleTxBean getTxBean(final int id) {
        getAllTx();
        return (RoleTxBean)UserMessUntil.allTx.getTxmap().get(Integer.valueOf(id));
    }

    public static AllTx getAllTx() {
        String cacheKey = "allTx";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllTx) entry.value;
        }

        if (UserMessUntil.allTx == null) {
            DownLoadTxt.getDownLoadTxt().initMes("tx.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allTx));
        return UserMessUntil.allTx;
    }

    public static void setAllTx(final AllTx allTx) {
        UserMessUntil.allTx = allTx;
        cache.put("allTx", new CacheEntry(allTx));
    }

    public static String getTYC(final String type) {
        return (String)getAllTYC().get(type);
    }

    public static Map<String, String> getAllTYC() {
        String cacheKey = "allTYC";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (Map<String, String>) entry.value;
        }

        if (UserMessUntil.allTYC == null) {
            DownLoadTxt.getDownLoadTxt().initMes("tyc.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allTYC));
        return UserMessUntil.allTYC;
    }

    public static void setAllTYC(final Map<String, String> allTYC) {
        UserMessUntil.allTYC = allTYC;
        cache.put("allTYC", new CacheEntry(allTYC));
    }

    public static aCard getACard(final int id) {
        return (aCard)getaCardMap().get(Integer.valueOf(id));
    }

    public static Map<Integer, aCard> getaCardMap() {
        String cacheKey = "allACard";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (Map<Integer, aCard>) ((AllACard) entry.value).getaMap();
        }

        if (UserMessUntil.allACard == null) {
            DownLoadTxt.getDownLoadTxt().initMes("acard.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allACard));
        return UserMessUntil.allACard.getaMap();
    }

    public static void setAllACard(final AllACard allACard) {
        UserMessUntil.allACard = allACard;
        cache.put("allACard", new CacheEntry(allACard));
    }

    public static Title getTitle(final String titleName) {
        return (Title)getAllTitle().getTitleMap().get(titleName);
    }

    public static AllTitleBean getAllTitle() {
        String cacheKey = "allTitle";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllTitleBean) entry.value;
        }

        if (UserMessUntil.allTitle == null) {
            DownLoadTxt.getDownLoadTxt().initMes("title.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allTitle));
        return UserMessUntil.allTitle;
    }

    public static void setAllTitle(final AllTitleBean allTitle) {
        UserMessUntil.allTitle = allTitle;
        cache.put("allTitle", new CacheEntry(allTitle));
    }

    public static AllEventModelBean getAllEventMap() {
        String cacheKey = "allEvent";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllEventModelBean) entry.value;
        }

        if (UserMessUntil.allEvent == null) {
            DownLoadTxt.getDownLoadTxt().initMes("event.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allEvent));
        return UserMessUntil.allEvent;
    }

    public static EventModel getEventModel(final Integer gId) {
        return (EventModel)getAllEventMap().getAllEventModelMap().get(gId);
    }

    public static void setAllEvent(final AllEventModelBean allEvent) {
        UserMessUntil.allEvent = allEvent;
        cache.put("allEvent", new CacheEntry(allEvent));
    }

    public static TaskData getTaskData(final int taskId) {
        if (UserMessUntil.allTask == null) {
            DownLoadTxt.getDownLoadTxt().initMes("task.txt");
        }
        return (TaskData)UserMessUntil.allTask.getAllTaskData().get(Integer.valueOf(taskId));
    }

    public static TaskSet getTaskSet(final int taskSetId) {
        if (UserMessUntil.allTask == null) {
            DownLoadTxt.getDownLoadTxt().initMes("task.txt");
        }
        return (TaskSet)UserMessUntil.allTask.getAllTaskSet().get(Integer.valueOf(taskSetId));
    }

    public static AllTask getAllTask() {
        String cacheKey = "allTask";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllTask) entry.value;
        }

        if (UserMessUntil.allTask == null) {
            DownLoadTxt.getDownLoadTxt().initMes("task.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allTask));
        return UserMessUntil.allTask;
    }

    public static void setAllTask(final AllTask allTask) {
        UserMessUntil.allTask = allTask;
        cache.put("allTask", new CacheEntry(allTask));
    }

    public static PalData getPalData(final int id) {
        return (PalData)getAllPal().getAllPalData().get(Integer.valueOf(id));
    }

    public static void setAllMountShouhu(AllMountShouhu allMountShouhu) {
        UserMessUntil.allMountShouhu = allMountShouhu;
        cache.put("allMountShouhu", new CacheEntry(allMountShouhu));
    }

    public static AllPal getAllPal() {
        String cacheKey = "allPal";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllPal) entry.value;
        }

        if (UserMessUntil.allPal == null) {
            DownLoadTxt.getDownLoadTxt().initMes("pal.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allPal));
        return UserMessUntil.allPal;
    }

    public static void setAllPal(final AllPal allPal) {
        UserMessUntil.allPal = allPal;
        cache.put("allPal", new CacheEntry(allPal));
    }

    public static allPetExchange getAllPetExchange() {
        String cacheKey = "allPetExchange";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (allPetExchange) entry.value;
        }

        if (UserMessUntil.allPetExchange == null) {
            DownLoadTxt.getDownLoadTxt().initMes("petExchange.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allPetExchange));
        return UserMessUntil.allPetExchange;
    }

    public static petExchange getPetExchange(final Integer eid) {
        return (petExchange)getAllPetExchange().getAllPetExchange().get(eid);
    }

    public static void setAllPetExchange(final allPetExchange allPetExchange) {
        UserMessUntil.allPetExchange = allPetExchange;
        cache.put("allPetExchange", new CacheEntry(allPetExchange));
    }

    public static allItemExchange getAllItemExchange() {
        String cacheKey = "allItemExchange";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (allItemExchange) entry.value;
        }

        if (UserMessUntil.allItemExchange == null) {
            DownLoadTxt.getDownLoadTxt().initMes("itemExchange.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allItemExchange));
        return UserMessUntil.allItemExchange;
    }

    public static ItemExchange getItemExchange(Integer eid) {
        return (ItemExchange)getAllItemExchange().getAllItemExchange().get(eid);
    }

    public static void setAllItemExchange(allItemExchange allItemExchange) {
        UserMessUntil.allItemExchange = allItemExchange;
        cache.put("allItemExchange", new CacheEntry(allItemExchange));
    }

    public static allGoodsExchange getAllGoodsExchange() {
        String cacheKey = "allGoodsExchange";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (allGoodsExchange) entry.value;
        }

        if (UserMessUntil.allPetExchange == null) {
            DownLoadTxt.getDownLoadTxt().initMes("goodsExchange.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allGoodsExchange));
        return UserMessUntil.allGoodsExchange;
    }

    public static GoodsExchange getGoodsExchange(Integer eid) {
        return (GoodsExchange)getAllGoodsExchange().getAllGoodsExchange().get(eid);
    }

    public static void setAllGoodsExchange(allGoodsExchange allGoodsExchange) {
        UserMessUntil.allGoodsExchange = allGoodsExchange;
        cache.put("allGoodsExchange", new CacheEntry(allGoodsExchange));
    }

    public static AllActive getAllActive() {
        String cacheKey = "allActive";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllActive) entry.value;
        }

        if (UserMessUntil.allActive == null) {
            DownLoadTxt.getDownLoadTxt().initMes("active.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allActive));
        return UserMessUntil.allActive;
    }

    public static void setAllActive(final AllActive allActive) {
        UserMessUntil.allActive = allActive;
        cache.put("allActive", new CacheEntry(allActive));
    }

    public static AllAchieve getAllAchieve() {
        String cacheKey = "allAchieve";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllAchieve) entry.value;
        }

        if (UserMessUntil.allAchieve == null) {
            DownLoadTxt.getDownLoadTxt().initMes("achieve.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allAchieve));
        return UserMessUntil.allAchieve;
    }

    public static void setAllAchieve(final AllAchieve allAchieve) {
        UserMessUntil.allAchieve = allAchieve;
        cache.put("allAchieve", new CacheEntry(allAchieve));
    }

    public static AllLianHua getAllLianHua() {
        String cacheKey = "allLianHua";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllLianHua) entry.value;
        }

        if (UserMessUntil.allLianHua == null) {
            DownLoadTxt.getDownLoadTxt().initMes("lh.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allLianHua));
        return UserMessUntil.allLianHua;
    }

    public static void setAllLianHua(final AllLianHua all) {
        UserMessUntil.allLianHua = all;
        cache.put("allLianHua", new CacheEntry(all));
    }

    public static AllMeridians getAllMeridians() {
        String cacheKey = "allMeridians";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllMeridians) entry.value;
        }

        if (UserMessUntil.allMeridians == null) {
            DownLoadTxt.getDownLoadTxt().initMes("meridians.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allMeridians));
        return UserMessUntil.allMeridians;
    }

    public static void setAllMeridians(final AllMeridians allMeridians) {
        UserMessUntil.allMeridians = allMeridians;
        cache.put("allMeridians", new CacheEntry(allMeridians));
    }

    public static GMshopItemBean getAllGMshopItem() {
        String cacheKey = "allGMshopItem";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (GMshopItemBean) entry.value;
        }

        if (UserMessUntil.allGMshopItem == null) {
            DownLoadTxt.getDownLoadTxt().initMes("GMshopItem.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allGMshopItem));
        GMshopItemBean bean = UserMessUntil.allGMshopItem;
        return bean;
    }

    public static void setAllGMshopItem(final GMshopItemBean allGMshopItem) {
        UserMessUntil.allGMshopItem = allGMshopItem;
        cache.put("allGMshopItem", new CacheEntry(allGMshopItem));
    }

    public static ConfigureBean getConfigureBean() {
        String cacheKey = "allConfigure";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (ConfigureBean) entry.value;
        }

        if (UserMessUntil.allConfigure == null) {
            DownLoadTxt.getDownLoadTxt().initMes("configure.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allConfigure));
        ConfigureBean bean = UserMessUntil.allConfigure;
        return bean;
    }

    public static Goodstable getgoodstablefromname(String  name){
        getGoodsBean();
        for (Goodstable goodstable:UserMessUntil.goodsBean.getAllGoodsMap().values()){
            if (goodstable.getGoodsname().equals(name))
                return goodstable;
        }
        return null;
    }

    public static void setConfigureBean(ConfigureBean allConfigure) {
        UserMessUntil.allConfigure = allConfigure;
        cache.put("allConfigure", new CacheEntry(allConfigure));
    }

    static {
        RewardHallArr = (List<RewardHall>)new ArrayList();
        friendtables = (List<Friendtable>)new ArrayList();
        petListTable = (List<RoleSummoning>)new ArrayList();
    }

    public static GlowFilter getFmSkillUpgradeParameters() {
        return null;
    }

    public static FlyConfig getFlyConfig() {
        return null;
    }

    public static List<RoleSummoning> getDepositPetListTable() {
        return depositPetListTable;
    }

    public static void setDepositPetListTable(List<RoleSummoning> depositPetListTable) {
        UserMessUntil.depositPetListTable = depositPetListTable;
    }

    public static PetExpBean getPetExp() {
        String cacheKey = "petExp";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (PetExpBean) entry.value;
        }

        if (UserMessUntil.petExp == null) {
            DownLoadTxt.getDownLoadTxt().initMes("petexp.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.petExp));
        return UserMessUntil.petExp;
    }

    public static List<String> getAllshaoxiang() {
        return allshaoxiang;
    }

    public static void setAllshaoxiang(List<String> allshaoxiang) {
        UserMessUntil.allshaoxiang = allshaoxiang;
        cache.put("allshaoxiang", new CacheEntry(allshaoxiang));
    }

    public static ConcurrentHashMap<String, ShaoXiangLimit> getAllshaoxianglimit() {
        return allshaoxianglimit;
    }

    public static void setAllshaoxianglimit(ConcurrentHashMap<String, ShaoXiangLimit> allshaoxianglimit) {
        UserMessUntil.allshaoxianglimit = allshaoxianglimit;
    }

    public static void setPetExp(final PetExpBean petExp) {
        UserMessUntil.petExp = petExp;
        cache.put("petExp", new CacheEntry(petExp));
    }

    private static List<Mount>mountList=new ArrayList<>();
    public static List<Mount>  getMountlsit(){
        return mountList;
    }
    public static void setMountList(List<Mount>list){
        mountList=list;
    }

    public static AllHallucination getAllHallucination() {
        String cacheKey = "allHallucination";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllHallucination) entry.value;
        }

        if (UserMessUntil.allHallucination == null) {
            DownLoadTxt.getDownLoadTxt().initMes("Hallucination.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allHallucination));
        return UserMessUntil.allHallucination;
    }

    public static void setAllHallucination(AllHallucination allHallucination) {
        UserMessUntil.allHallucination = allHallucination;
        cache.put("allHallucination", new CacheEntry(allHallucination));
    }

    public static AutoActiveRedisBaseBean getAutoActiveRedisBaseBean() {
        return autoActiveRedisBaseBean;
    }

    public static void setAutoActiveRedisBaseBean(AutoActiveRedisBaseBean autoActiveRedisBaseBean) {
        UserMessUntil.autoActiveRedisBaseBean = autoActiveRedisBaseBean;
    }

    public static AutoActiveBaseBean getAlltutoactive() {
        return alltutoactive;
    }

    public static void setAlltutoactive(AutoActiveBaseBean alltutoactive) {
        UserMessUntil.alltutoactive = alltutoactive;
        cache.put("alltutoactive", new CacheEntry(alltutoactive));
    }

    public static AutoActiveBaseBean getAllAutoActive() {
        String cacheKey = "alltutoactive";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AutoActiveBaseBean) entry.value;
        }

        if (UserMessUntil.alltutoactive == null) {
            DownLoadTxt.getDownLoadTxt().initMes("autoactive.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.alltutoactive));
        return UserMessUntil.alltutoactive;
    }

    public static void addAlltutoactive(AutoActiveReidsBase aarb) {
        if(UserMessUntil.alltutoactive!=null && UserMessUntil.alltutoactive.getAllautobase() !=null && UserMessUntil.alltutoactive.getAllautobase().size()>0){
            for(AutoActiveBase aab:UserMessUntil.alltutoactive.getAllautobase()){
                if(aab.getGuide()!=null){
                    String guide = aab.getGuide();
                    String[] v = guide.split("\\|");
                    if (v.length >= 5) {
                        if(Integer.parseInt(v[3]) == 0){
                            if (StringUtils.isNotBlank(v[4]) && v[4].startsWith("系统野怪设置")) {
                                String[] yg = v[4].split("=");
                                if(yg.length == 5){
                                    //int roobtId = Integer.valueOf(yg[1]);
                                    if(aarb.getId() == aab.getId()){
                                        aab.setComNum(aarb.getComNum());
                                    }
                                }

                            }
                        }
                    }
                }
            }
        }
    }

    public static Achievement getAchievement(int id) {
        return UserMessUntil.allAchievement.getAllAchievement().get(id);
    }

    public static AllAchievement getAllAchievement() {
        String cacheKey = "allAchievement";
        CacheEntry entry = (CacheEntry) cache.get(cacheKey);
        if (entry != null && !entry.isExpired() && entry.value != null) {
            return (AllAchievement) entry.value;
        }

        if (UserMessUntil.allAchievement == null) {
            DownLoadTxt.getDownLoadTxt().initMes("achievement.txt");
        }

        cache.put(cacheKey, new CacheEntry(UserMessUntil.allAchievement));
        return UserMessUntil.allAchievement;
    }

    public static void setAllAchievement(final AllAchievement allAchievement) {
        UserMessUntil.allAchievement = allAchievement;
        cache.put("allAchievement", new CacheEntry(allAchievement));
    }
}
